package com.tahado.service;

import java.util.Collection;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.Query;
import javax.jws.WebService;

import com.tahado.dao.PMF;
@WebService
public class User {
	public static String add(String name, String accesstoken, String fbId) {
		com.tahado.model.User u = new com.tahado.model.User(name, accesstoken,
				fbId);
		PersistenceManager pm = PMF.get().getPersistenceManager();
		String usersString = "";

		pm.currentTransaction().begin();
		pm.makePersistent(u);
		pm.currentTransaction().commit();
		pm.close();
		
		PersistenceManager pm2 = PMF.get().getPersistenceManager();
		
		Query query = pm2.newQuery(com.tahado.model.User.class);

		Collection<com.tahado.model.User> allUsers = (Collection) query.execute();
		System.out.println(allUsers .size());
		for (com.tahado.model.User user : allUsers) {
			usersString = usersString + user + "</br>";

		}

		pm2.close();
		
	

		return usersString;

	}

}
